<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>07-mapGetters</title>
    </head>
    <body>
        <div id="app">
            父
            <div v-for="i in dayu18">{{i.id}}-- {{i.name}}</div>

            <child></child>
        </div>
        <script src='../js/vue.js'></script>
        <script src="../js/vuex.js"></script>
        <script>
            let mapState = Vuex.mapState;
            let mapGetters=Vuex.mapGetters;

            let child = {
                template: `
                  <div>
                  子
                  <div v-for="i in dayu18">{{ i.id }}--{{ i.name }}</div>
                  </div>`,
                computed: {
                    ...mapGetters(['dayu18'])
                },
            }

            let store = new Vuex.Store({
                state: {
                    stu: [
                        {"id": 1, name: "熊大", age: 20},
                        {"id": 2, name: "熊二", age: 16},
                        {"id": 3, name: "光头强", age: 19},
                        {"id": 4, name: "王老板", age: 15},
                    ]
                },
                getters: {
                    dayu18(state) {
                        return state.stu.filter(item => item.age >= 18)
                    }
                }
            })

            let vm = new Vue({
                el: "#app",
                computed: {
                    ...mapState(['stu']),
                    ...mapGetters(['dayu18'])
                },
                store,
                data: {},
                components: {
                    child
                }
            });
        </script>
    </body>
</html>